/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kkks.spring_rest.tick.utils;

import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Administrator
 */
public class ConvertHelper {

    public static int booleanToInt(boolean value) {
        if (value) {
            return 1;
        } else {
            return 0;
        }
    }

    public static int DateToInt(Date date) {
        if(date!= null)
        {
        return (int) (date.getTime() / 1000);}
        else
        {
            return 0;
        }
    }

    public static Date IntToDate(int seconds) {
        if (seconds < 1) {
            return null;
        } else {
            Calendar c = Calendar.getInstance();
            c.setTime(new Date(0));
            c.add(Calendar.SECOND, seconds);
            return c.getTime();
        }
    }

    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        //c.add(Calendar.MONTH, -2);
        //1298592386 1302862821
        System.out.println(ConvertHelper.IntToDate(1302862821));
        System.out.println(ConvertHelper.DateToInt(c.getTime()));
    }
    
    public static String getAnonyousEmail(String email)
    {
        int indexOfAt = email.indexOf("@");
        if(indexOfAt > 0)
        {
            return "****" + email.substring(indexOfAt);
        }
        else
        {
            return email;
        }
    }
}
